

-- Namespace
	local _,mod = ...


-- Constants
	local scale = .8
	
	local font = {mod.path..'media\\bavaria.ttf',8/scale,'OUTLINEMONOCHROME'}
	
	local c_bg =  {.1,.1,.1,.5}
	local c_border = {.07,.07,.07}
	
	local default_anchor = {'BOTTOMRIGHT',-24/scale,42/scale}


-- Skin
	local function skin(tip)
		tip:SetBackdrop(nil)
		tip:SetScale(scale)
		
		local bg = tip:CreateTexture(nil,'BACKGROUND')
			bg:SetPoint('TOPLEFT',1/scale,-1/scale)
			bg:SetPoint('BOTTOMRIGHT',-1/scale,1/scale)
			bg:SetTexture(unpack(c_bg))
			tip.bg = bg
		
		local bL = tip:CreateTexture(nil,'BACKGROUND')
			bL:SetWidth(1/scale)
			bL:SetPoint('TOPLEFT') bL:SetPoint('BOTTOMLEFT')
			bL:SetTexture(unpack(c_border))
			tip.borderleft = bL
		
		local bR = tip:CreateTexture(nil,'BACKGROUND')
			bR:SetWidth(1/scale)
			bR:SetPoint('TOPRIGHT') bR:SetPoint('BOTTOMRIGHT')
			bR:SetTexture(unpack(c_border))
			tip.borderright = bR
		
		local bT = tip:CreateTexture(nil,'BACKGROUND')
			bT:SetHeight(1/scale)
			bT:SetPoint('TOPLEFT') bT:SetPoint('TOPRIGHT')
			bT:SetTexture(unpack(c_border))
			tip.bordertop = bT
		
		local bB = tip:CreateTexture(nil,'BACKGROUND')
			bB:SetHeight(1/scale)
			bB:SetPoint('BOTTOMLEFT') bB:SetPoint('BOTTOMRIGHT')
			bB:SetTexture(unpack(c_border))
			tip.borderbottom = bB
		
		local function skin_strings()
			local r = {tip:GetRegions()}
			for i = 1,#r do
				if r[i].SetFont then
					r[i]:SetFont(unpack(font))
					r[i]:SetShadowOffset(0,0)
				end
			end
			if tip:IsShown() then
				tip:Show()  -- Re-sizes the tooltip.
			end
		end
		
		tip:HookScript('OnShow',function(self)
			mod:timer_register(.1,false,skin_strings)
		end)
		
		tip.nfTooltip = true
	end
	
	local apply = {'GameTooltip','ShoppingTooltip1','ShoppingTooltip2',
		'ShoppingTooltip3','SmallTextTooltip','ItemRefTooltip',
		'ItemRefShoppingTooltip1','ItemRefShoppingTooltip2','ItemRefShoppingTooltip3'}
	
	for i = 1,#apply do
		local f = _G[apply[i]]
		if f and f:GetObjectType() == 'GameTooltip' then
			skin(f)
		end
	end


-- Anchoring
	hooksecurefunc('GameTooltip_SetDefaultAnchor',function(self,parent)
		if not self.nfTooltip then return end
		self:ClearAllPoints()
		self:SetPoint(unpack(default_anchor))
	end)
